 #***********************************************************************
 #* @file      SConscript
 #* @author    Dave Martin, DeVivo AST, Inc.  
 #* @date      2008/03/03
 #*
 #*  Copyright (C) 2008. DeVivo AST, Inc
 #*
 #*  This file is part of Jr Middleware.
 #*
 #*  Jr Middleware is free software: you can redistribute it and/or modify
 #*  it under the terms of the GNU Lesser General Public License as published by
 #*  the Free Software Foundation, either version 3 of the License, or
 #*  (at your option) any later version.
 #*
 #*  Jr Middleware is distributed in the hope that it will be useful,
 #*  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #*  GNU Lesser General Public License for more details.
 #*
 #*  You should have received a copy of the GNU Lesser General Public License
 #*  along with Jr Middleware.  If not, see <http://www.gnu.org/licenses/>.
 #*
 #************************************************************************
 
# Import base environment
import os
Import( 'baseEnv' )

# Here's where the good stuff starts...
API_Files = [
    'JuniorAPI.cpp',
    'JrSockets.cpp',
    'JuniorMgr.cpp',
    'OS.cpp',
    'JrLogger.cpp',
    'XmlConfig.cpp',
    'JUDPTransport.cpp',
    'JSerial.cpp',
    'ChecksumCRC.cpp',
    'TCPConnection.cpp',
    'JTCPTransport.cpp',
    'tinyxml/tinyxml.cpp',
    'tinyxml/tinyxmlerror.cpp',
    'tinyxml/tinyxmlparser.cpp'
]

# Define multiple environments for building and using
# the library as a Shared Library (dll or so).
dllenv = baseEnv.Clone()
dllenv.Append( CCFLAGS = ['-D__BUILD_DLL__'] ) 
dllenv.Append( LINKFLAGS = ['/DEF:Junior.DEF'] )
dllenv['SHOBJPREFIX'] = 'sh'
ocuenv = baseEnv.Clone()
ocuenv.Append( CCFLAGS = ['-D__USE_DLL__'] )                 

# On Windows, we generate a DLL for the API
# as well as a executable for the Run-Time Engine.
# The RTE must be linked to a static library, however,
# so we need to build both a static and a shared library.
# These are given different names to prevent confusion,
# but only the DLL (and associated lib) are intended 
# for release.
if os.name == "nt":

    apilib = dllenv.SharedLibrary( target = 'Junior',
                                   source = API_Files )
                                                                
    rteapp = baseEnv.Program( target = 'JuniorRTE',
							  source = ['JuniorRTE.cpp'] + API_Files )
							  
    baseEnv.Install( baseEnv['INSTALL_BINDIR'], 'Junior.dll' )							  
						
else:

    apilib = baseEnv.Library(  target = 'Junior',
                               source = API_Files )
                           
    rteapp = baseEnv.Program( target = 'JuniorRTE',
							  source = 'JuniorRTE.cpp',
							  LIBS = 'Junior' )
                           

baseEnv.Install( baseEnv['INSTALL_LIBDIR'], apilib )
baseEnv.Install( baseEnv['INSTALL_BINDIR'], rteapp )
baseEnv.Install( baseEnv['INSTALL_BINDIR'], 'jr_config.xml' )